<template>
  <div>
    <el-table :data="bannerList" border style="width: 100%">
      <el-table-column prop="id" label="编号"></el-table-column>
      <el-table-column prop="title" label="轮播图标题"></el-table-column>
      <el-table-column prop="address" label="图片">
        <template slot-scope="scope">
          <img :src="$pre + scope.row.img" alt />
        </template>
      </el-table-column>
      <el-table-column prop="date" label="状态">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status==1">启用</el-button>
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="willEdit(scope.row.id)">编辑</el-button>
          <v-delete @del="del(scope.row.id)"></v-delete>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { bannerDel } from "../../../request/api";
export default {
  data() {
    return {};
  },
  props: ["flag"],
  computed: {
    ...mapGetters({
      bannerList: "banner/bannerList"
    })
  },
  components: {},
  methods: {
    ...mapActions({
      reqBannerList: "banner/reqBannerList",
      reqBannerInfo: "banner/reqBannerInfo"
    }),
    // 点击删除
    del(id) {
      bannerDel({ id: id }).then(res => {
        if (res.data.code == 200) {
          this.reqBannerList();
        }
      });
    },
    // 点击编辑
    willEdit(id) {
      this.flag.isShow = true;
      this.flag.isAdd = false;
      this.reqBannerInfo(id);
    }
  },
  mounted() {
    this.reqBannerList();
  }
};
</script>
<style lang='less' scoped>
img {
  width: 100px;
  height: 100px;
}
</style>